<script>
function GetXmlHttpObject()
// JS function for 
// - calling the different steps of facecontest program.
// - show in the webpage the computing or done of the different parts
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }document.getElementById(which).style.visibility = 'visible';
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

function CallDoStuff1(stringa)
{
    //alert(stringa);

		//reloadOnceOnly(); //You can call this via the body tag if desired

    document.getElementById('myFinal').style.visibility='hidden';
    document.getElementById('myClick').style.visibility='hidden';
    document.getElementById('step01').style.visibility='hidden';
    document.getElementById('step02').style.visibility='hidden';
    document.getElementById('step03').style.visibility='hidden';
    //document.getElementsByTagName('button').style.disabled='true';
    show('computationON');
    show('step01');
    document.getElementById('step01').style.visibility='visible';
  	
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="retrieve_pictures.php?";
	url+=stringa;
    param=stringa;
    xmlhttp.onreadystatechange=stateChanged1;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    }
    
function CallDoStuff2(stringa2)
{
	
    show('computationON');
    show('step02');
    document.getElementById('step02').style.visibility='visible';
  	
    xmlhttp2=GetXmlHttpObject();
    if (xmlhttp2==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="find_faces.php?";
    url+=stringa2;
    xmlhttp2.onreadystatechange=stateChanged2;
    xmlhttp2.open("GET",url,true);
    xmlhttp2.send(null);
    }

function CallDoStuff3(stringa3)
{
	
    show('computationON');
    show('step03');
    document.getElementById('step03').style.visibility='visible';
  	
    xmlhttp3=GetXmlHttpObject();
    if (xmlhttp3==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="render_video.php?";
    url+=stringa3;
    xmlhttp3.onreadystatechange=stateChanged3;
    xmlhttp3.open("GET",url,true);
    xmlhttp3.send(null);
    }
    
    
function Finalize(stringa4)
{
	
    show('myFinal');
    document.getElementById('myFinal').style.visibility='visible';
    document.getElementById('myClick').style.visibility='visible';

  	
    xmlhttp4=GetXmlHttpObject();
    if (xmlhttp4==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="logging.php?";
    url+=stringa4;
    xmlhttp4.onreadystatechange=stateChanged4;
    xmlhttp4.open("GET",url,true);
    xmlhttp4.send(null);
    }

function Upload_WriteWall(stringa5)
{
    show('myClick');
    xmlhttp5=GetXmlHttpObject();
    if (xmlhttp5==null)
    {
    alert ("Browser does not support HTTP Request");
    return;
    }
    var url="upload_postwall.php?";
    url+=stringa5;
    xmlhttp5.onreadystatechange=stateChanged5;
    xmlhttp5.open("GET",url,true);
    xmlhttp5.send(null);
    }



function stateChanged1()
{
    if (xmlhttp.readyState==4)
    {
    	if(xmlhttp.status==200){
		document.getElementById('step01').innerHTML+=" done!<br>";
		var result1 = xmlhttp.responseText;
		CallDoStuff2(result1);
        }
    }
}

function stateChanged2()
{
    if (xmlhttp2.readyState==4)
    {
    	if(xmlhttp2.status==200){
		document.getElementById('step02').innerHTML+=" done!<br>";
		var result2 = xmlhttp2.responseText;
		CallDoStuff3(result2);
        }
    }
}

function stateChanged3()
{
    if (xmlhttp3.readyState==4)
    {
    	if(xmlhttp3.status==200){
		document.getElementById('step03').innerHTML+=" done!<br>";
		hide('computationON');
		var result3 = xmlhttp3.responseText;
		Finalize(result3);
		
        }
    }
}

function stateChanged4()
{
    if (xmlhttp4.readyState==4)
    {
    	if(xmlhttp4.status==200){
		var result4 = xmlhttp4.responseText;
		Upload_WriteWall(result4);
		
        }
    }
}


function stateChanged5()
{
    if (xmlhttp5.readyState==4)
    {
    	if(xmlhttp5.status==200){
		var result5 = xmlhttp5.responseText;
		document.getElementById('myClick').innerHTML+=result5;
	
        }
    }
}

function hide(which) {
	document.getElementById(which).style.visibility = 'hidden';
}
function show(which) {
	document.getElementById(which).style.visibility = 'visible';
}
</script>



</script>
